<?php
/*
 * Created on Feb 24, 2009
 * Form_Search: ANH
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 
 class place_Form_PlaceSearch extends Zend_Form
 {
     protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );
    /**
     * init() is the initialization routine called when Zend_Form objects are 
     * created. In most cases, it make alot of sense to put definitions in this 
     * method, as you can see below.  This is not required, but suggested.  
     * There might exist other application scenarios where one might want to 
     * configure their form objects in a different way, those are best 
     * described in the manual:
     *
     * @see    http://framework.zend.com/manual/en/zend.form.html
     * @return void
     */ 
    public function cluBuild($params)
    {
    	$sess = new Zend_Session_Namespace(CLU_NS);
        // set the method for the display form to POST
        $this->setMethod('GET');
       	$this->setAction($params['action_url']);
        
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(627) 
                                                               ));
        $submit->setAttrib("class", 'box_search_bottom');
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
        
		//namePlace: 
		$nameplace = new Zend_Form_Element_Text('raw_name', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'keywordInput', 'size'=>'20',
                                                                   'required' => true));
        $nameplace->addDecorators($this->_noDecorator);
        $this->addElement($nameplace);
        
        
        $searchplace = new Zend_Form_Element_Text('search_name', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'keywordInput', 'size'=>'60',
                                                                   'required' => true));
        $searchplace->addDecorators($this->_noDecorator);
        $this->addElement($searchplace);
        
        
        
        /*
        //City
        $city_id = new Zend_Form_Element_Select('city_id',array('disableLoadDefaultDecorators' => true,
                                                             'required' => true));
        $city_id->addMultiOption('0','--'.t(717).'--');
        $table = new place_Model_City();
        $topCities = Zend_Registry::get('configuration')->topCities->toArray();
        $city_id->addMultiOptions($topCities)
		        ->setAttrib('disable', array('1a'));
        foreach ($table->fetchAll() as $c) {
        	if($sess->viewLang == 'vi')	
            	$city_id->addMultiOption($c['city_id'],$c['city_name']);
            else
            	$city_id->addMultiOption($c['city_id'],VN_unaccent($c['city_name']));
            
        	$city_id->addDecorators($this->_noDecorator);
        }
        $this->addElement($city_id);
        */
        //CityId
        $cityId = new Zend_Form_Element_Select('cityId',array('disableLoadDefaultDecorators' => true,
                                                             'required' => true));
        $cityId->addMultiOption('0','--'.t(717).'--');
        $table = new place_Model_City();
        $topCities = Zend_Registry::get('configuration')->topCities->toArray();
        $cityId->addMultiOptions($topCities)
		        ->setAttrib('disable', array('1a'));
        foreach ($table->fetchAll() as $c) {
            if($sess->viewLang == 'vi')	
            	$cityId->addMultiOption($c['city_id'],$c['city_name']);
            else
            	$cityId->addMultiOption($c['city_id'],VN_unaccent($c['city_name'])); 
        	$cityId->addDecorators($this->_noDecorator);
        }
        $this->addElement($cityId);
        /*
        //District
       $district_id = new Zend_Form_Element_Select('district_id',array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $district_id->addMultiOption('0','--'.t(718).'--')
                    ->setRegisterInArrayValidator(false)	
                    ->addDecorators($this->_noDecorator);
 
        $this->addElement($district_id);
        /*
        //Village
        $village_id = new Zend_Form_Element_Select('village_id',array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $village_id->addMultiOption('0','--'.__('No Village').'--')
                   ->setRegisterInArrayValidator(false)	
                   ->addDecorators($this->_noDecorator);
 
        $this->addElement($village_id);
        //Root Type
        $category = new Zend_Form_Element_MultiCheckbox('category',  array('disableLoadDefaultDecorators' => true,
                                                                 ));
		$mCategory = new category_Model_Category();
		$mCategory->setTables('place');
        foreach ($mCategory->getRootType('Root_Place') as $c) {
            $category->addMultiOption('0','--'.t(732).'--');
            $category->addMultiOption($c['id'], p($c['name']));
        	$category->addDecorators($this->_noDecorator);
        }
        $this->addElement($category);
        */
        
        //rtype
//        $rtype = new Zend_Form_Element_MultiCheckbox('rtype',  array('disableLoadDefaultDecorators' => true,
//                                                                 'required' => true));
//		$rtype->setRegisterInArrayValidator(false)
////			 ->addMultiOption('0','--'.t(112).'--')
//			 ->setAttrib('class', 'rtype-check-box')
//			 ->addDecorators($this->_noDecorator);
//        $this->addElement($rtype);
        
        /*
        if ($params['cluSearchMode'] == 'simpleSearch')
        	return;
        
        //fee        
        $fee = new Zend_Form_Element_Text('fee', array('disableLoadDefaultDecorators' => true,
                                                                 'class' => 'inputText',
                                                                 'required' => true));
        $fee->addDecorators($this->_noDecorator);
        $this->addElement($fee);
        
        // To from
        $toFee = new Zend_Form_Element_Text('to_fee', array('disableLoadDefaultDecorators' => true,
                                                                 'class' => 'inputText',
                                                                 'required' => true));
        $toFee->addDecorators($this->_noDecorator);
        $this->addElement($toFee);
        
        //fee_basis
        $fee_basis = new Zend_Form_Element_Select('fee_basis', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $fee_basis->addMultiOption('0','--'.t(97).'--')
                  ->addMultiOption('entrance',t(733))
                  ->addMultiOption('hour',t(734))
                  ->addMultiOption('day',t(735))
                  ->addMultiOption('week',t(736))
                  ->addMultiOption('month',t(737))
                  ->addDecorators($this->_noDecorator);
        $this->addElement($fee_basis);
        
        //fee_currency
        $fee_currency = new Zend_Form_Element_Select('fee_currency', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $fee_currency->addMultiOption('0','--'.t(97).'--')
                     ->addMultiOption('VND',__('VND'))
                     ->addMultiOption('USD',__('USD'))
                     ->addMultiOption('EURO',__('EURO'))
                     ->addMultiOption('CNY',__('CNY'))
                     ->addMultiOption('JPY',__('JPY'))
                     ->addDecorators($this->_noDecorator);
        $this->addElement($fee_currency);
        
		//payment_method
        $payment_method = new Zend_Form_Element_MultiCheckbox('payment_method', array(
													    'multiOptions' => array(
													        'cash' => t(798),
													        'creditcard' => t(799),
													    )
													));
		
		$this->addElement($payment_method);	
		
		//meals
		/*
       $meals = new Zend_Form_Element_MultiCheckbox('meals', array(
												    'multiOptions' => array(
												        'morning' => t(738),
												        'noon' => t(739),
												        'evening' => t(740),
												        'night' => t(741),
												    )
												));
        $meals->addDecorators($this->_noDecorator);
        $this->addElement($meals);
	        
	    //delivery
       	$delivery = new Zend_Form_Element_Checkbox('delivery');
      	 $delivery->addDecorators($this->_noDecorator)
	    	        ->setCheckedValue(true);
	   	$this->addElement($delivery);
        
        // Street_Name
        $str_name = new Zend_Form_Element_Text('address7', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   'required' => false));
        $str_name->addDecorators($this->_noDecorator);
        $this->addElement($str_name);
        
        // Street_Number
        $str_number = new Zend_Form_Element_Text('address8', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   'required' => false));
        $str_number->addDecorators($this->_noDecorator);
        $this->addElement($str_number);
        */
        /*
        // Built_Year
        $built__year = new Zend_Form_Element_Text('built_year', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   'required' => false));
        $built__year->addDecorators($this->_noDecorator);
        $this->addElement($built__year);
        
        //To Built_year
        $to_built__year = new Zend_Form_Element_Text('to_built_year', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   'required' => false));
        $to_built__year->addDecorators($this->_noDecorator);
        $this->addElement($to_built__year);
        
        
        //place_perpage
        $place_perpage = new Zend_Form_Element_Select('place_perpage', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $place_perpage//->addMultiOption('0','--'.__('Choose').'--')
                    ->addMultiOption('10', 10)
                    ->addMultiOption('20', 20)
                    ->addMultiOption('50', 50)
                    ->addDecorators($this->_noDecorator);
        $this->addElement($place_perpage);
        
        if ($params['cluSearchMode'] == 'fullSearch')
        	return;
         // orderBy
         $orderBy = new Zend_Form_Element_Select('orderBy',  
         		                array('disableLoadDefaultDecorators' => true));
//        $orderBy->addMultiOption('time',__('Time'))
        $orderBy->addMultiOption('post_time','Post time')
                ->addMultiOption('city_id','City id')
                ->addDecorators($this->_noDecorator);
        $this->addElement($orderBy);
        
        // ASCorDESC
        $asc_or_desc = new Zend_Form_Element_Select('asc_or_desc',  
                         array('disableLoadDefaultDecorators' => true));
        $asc_or_desc->addMultiOption('ASC',t(122))
               ->addMultiOption('DESC',t(123))
               ->addDecorators($this->_noDecorator);
        $this->addElement($asc_or_desc);// orderBy
		//get_article
        $get_Article = new Zend_Form_Element_Select('getArticle', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $get_Article->addMultiOption('0',t(132))
                    ->addMultiOption('1', t(131))
                    ->addDecorators($this->_noDecorator);
        $this->addElement($get_Article);
        //userId
        $userId = new Zend_Form_Element_Text('poster_id', array('disableLoadDefaultDecorators' => true,
                                                         'class' => 'inputText',
                                                         'required' => false));
        $userId->addDecorators($this->_noDecorator);
        $this->addElement($userId);
        
        //status
        $status = new Zend_Form_Element_Select('status',array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $status->addMultiOption('0','--'.t(61).'--')
    			->addMultiOption('featured',t(33))
    			->addMultiOption('published',t(34))
               ->addMultiOption('queued',t(35))
               ->addMultiOption('unpublished',t(36))
               ->addMultiOption('deleted',t(37))
                ->setRegisterInArrayValidator(false)	
                ->addDecorators($this->_noDecorator);
        $this->addElement($status);
        
        // place Id
        $placeId = new Zend_Form_Element_Text('id', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   /*'required' => true*/
                                                          /*));
		$placeId->addDecorators($this->_noDecorator);
        $this->addElement($placeId);
        */
    }
    
    public function populateCategory($data)
    {
    	/*
    	//populate districts
    	if(!empty($data['city_id']))
    	{
    		$mDistrict = new place_Model_District();
			foreach ($mDistrict->getDistricts($data['city_id']) as $dis) 
	            $this->district_id->addMultiOption($dis['district_id'], $dis['district_name']);
    	}
    	
    	if(isset($data['rtype']))
    	{
       		if(!isset($data['category']))
       		{
		       	$mCategory = new category_Model_Category();
				$mCategory->setTables('place');
				foreach ($mCategory->getTree($data['rtype'], 0, 1) as $c)
				{ 
				    $data['category'] = $c['pid'];
		        	break;
				}
       		}
    	}
		//populate villages
		/*
		if(isset($data['district_id']))
		{
			$mVillage = new place_Model_Village();
			$districtId = $data["district_id"];
			foreach ($mVillage->getVillages($districtId) as $v) 
			{
		           $this->village_id->addMultiOption($v['village_id'], $v['village_name']);
			}
		}
		*/
		//populate rtype
//		if(isset($data['category']))
//		{
//			$mCategory = new category_Model_Category();
//			$mCategory->setTables('place');
//			foreach ($mCategory->getTree($data['category'], 1, 1) as $c) 
//	            $this->rtype->addMultiOption($c['id'], $c['displayName']);
//		}
		if(!empty($data))
		{
			$this->populate($data);
		}
    }
    
    public function populateCity($data)
    {
    	if(isset($data['city_id']))
    		$data['cityId'] = $data['city_id'];
    	
    	$this->populate($data);
    }
 }
?>
